<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<link rel="stylesheet" href="../../layui/css/layui.css">
<link rel="stylesheet" href="../../layui/dtree/dtree.css">
<link rel="stylesheet" href="../../layui/dtree/font/iconfont.css">
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../layui/dtree/dtree.js"></script>
<head>
<meta charset="UTF-8">
<title>部门级别树</title>
</head>
<body>
<h1>高新区督查部门级别树</h1>
<div style="height: 700px; overflow: auto;" id="toolbarDiv3">
  <ul id="toolbarTree3" class="dtree" data-id="0"></ul>
</div>
<script>
layui.config({
	  base: '../layui/dtree/' //配置 layui 第三方扩展组件存放的基础目录
	}).extend({
	  dtree: 'dtree' //定义该组件模块名
	}).use(['element','layer', 'dtree'], function(){
		var layer = layui.layer,
	    dtree = layui.dtree,
	    $ = layui.$;
	var leaf=null;
	dtree.render({
	  elem: "#toolbarTree3",
	  url: "../dept/list",
	  toolbar:true,
	  toolbarScroll:"#toolbarDiv3",
	  toolbarFun: {
		    addTreeNode: function(treeNode){
		    	var nodeId=0;
		    	$.ajax({
		              url:'addDeptType',
		              type:'post',
		              data:{'did':treeNode.parentId,'dname':treeNode.addNodeName},
		              dataType: 'json',                
		              success: function(nodeId){
		            	  if(nodeId!=null){
		            		  treeNode.nodeId=nodeId;
		            	  }
		            	  }
		              }); 
		      return treeNode.nodeId;
		    },
		    editTreeNode: function(treeNode){
		    	var param = $.ajax({
		    		async:false,
		    		url:'updateDeptType',
		    		type:'post',
					data:{'did':treeNode.nodeId,'dname':treeNode.editNodeName},
					dataType: 'json',
					success: function(treenode){
		            	  if(treenode!=null){
		            		  return treenode;
		            	  }
		            	  }
		    		})
		      return param;
		    },
		     delTreeNode: function(treeNode){
		    	var data=false;
		    		$.ajax({
		              url:'deleteDeptType',
		              type:'post',
		              data:{'did':treeNode.nodeId},
		              dataType: 'json',                
		              success: function(data){
		            	  if(data==true){
		            		  return true;
		            	  }else{
		            		  return false;
		            	  }
		            	  }
		              }); 
		    		return true;
		    } 
		  }
	 // toolbarShow:["edit"],  // 这样就只会出现一个了
	});
	});

</script>
<!--  <ul id="demo"></ul>

<ul id="demo1" style="margin-top: 50px;"></ul>

<script>
layui.use('tree', function(){
	
	layui.$.post("showDeptTree",function(data){
		layui.tree({
		    elem: '#demo' //指定元素
		    ,nodes: data
		  });
	})
});
</script> -->
</body>
</html>